package com.designPattern.composite;

/**
 * @author mxs
 * 【组合模式】
 * 【解决问题】解决树形展示结构的问题
 * 【基本思路】
 * 将所有树的结点都继承自同一个树节点抽象类或者接口
 * 每一个父节点都聚合一个子结点的列表，存储所有子结点，并且完成接口的add()和remove(),完成对子类的增删的控制
 * 【优点】新增一个结点，不管是叶子结点还是非叶子结点，都容易加入到已有的树中
 * 避免了使用继承父类方案的，修改结点时候的耦合问题（难以修改）
 */
public class Test5 {
    public static void main(String[] args) {
        University university1 = new University("", "清华大学");
        University university2 = new University("", "北京大学");

        Collage collage1 = new Collage("计算机", "计算机学院");
        Collage collage2 = new Collage("金融", "金融学院");
        Collage collage3 = new Collage("保险", "保险学院");

        university1.add(collage1);
        university1.add(collage2);
        university1.add(collage3);

        collage1.add(new Department("","软件工程专业"));
        collage1.add(new Department("","计算机科学与技术专业"));
        collage1.add(new Department("","大数据专业"));

        collage2.add(new Department("","金融学"));
        collage2.add(new Department("","会计学"));
        collage2.add(new Department("","ACCA"));

        university1.print();
        System.out.println("***************************************");
        collage1.print();
        String gender = "my sex is female";
        String substring = gender.substring(30);
        System.out.println(substring);

    }
}
